import ajax from 'axios'
const home={
  namespaced:true,
  state:{
    NewsList:[],
    BannerList:[],
    tagHistoryList: ['你好','阿','唐人街','刺杀','李','达'],
  },
  mutations:{
    NewsList(state,info){
      state.NewsList=info ||[];
    },
    Banner(state,info){
      state.BannerList=info ||[];
    },
    saveTagHistory(state, item) {
      state.tagHistoryList.push(item)
      if(state.tagHistoryList.length===7){
        state.tagHistoryList[7]='▼'
      }
      }

  },
  actions:{
    getNewsList({commit}) {
      ajax.get('/api/news/index').then((res) => {
commit('NewsList',res.data.data)
      }).catch((error) => {
        console.log(error)
      })
    },
    getBanner({commit}) {
      ajax.get('/api/banner/getBanner').then((res) => {
        commit('Banner',res.data.data)
      }).catch((error) => {
        console.log(error)
      })
    },
    SaveTagHistory(context, item) {
      context.commit('saveTagHistory', item)
    },
  }
}
export default home
